// 引入request
import request from '../util/request.js';

const FlawRequest = {
    BASE_URL : "http://localhost:8086/qc",
    // 请求过程在这里开发，不在.vue文件中开发
    /**
     * 编码的自动生成
     */
    getCode(rulesName,callBack){
        let url = this.BASE_URL + "/rules/query";
        request.get(url,rulesName,callBack);
    },

    /**
     * 多条件分页查询与template_id相对应的数据
     */
    loadFlawItemByTemplateId(templateId, page, limit, callBack) {
        // 拼接url
        let url = this.BASE_URL + "/checkItem/queryByPageTemplate";
        // 构建参数对象
        let params = { templateId: templateId, page: page, limit: limit };
        // 调用request进行请求
        request.get(url, params, callBack);
    },


    /**
     * 多条件分页查询dict列表
     * @param flaw
     * @param callBack
     */
    loadFlawItem(checkItem, callBack){
        // 拼接url  /sys/queryByPage?xxx
        let url = this.BASE_URL + "/checkItem/queryByPage";
        // 调用request进行请求  http://lcation
        request.get(url,checkItem,callBack);
    },
    /**
     * 查询所有信息
     */
    loadFlawItemAll(callBack){
        let url = this.BASE_URL + "/checkItem/queryAll";
        request.get(url,null,callBack);
    },

    /**
     * 新增(所有的属性的添加)
     * @param flaw
     * @param callBack
     */
    addFlawItemTemplate(checkItem,callBack){
        let url = this.BASE_URL + "/checkItem/saveByTemplate"
        request.post(url,checkItem,callBack);
    },

    /**
     * 新增字典的API
     * @param flaw
     * @param callBack
     */
    addFlawItem(checkItem,callBack){
        let url = this.BASE_URL + "/checkItem/save"
        request.post(url,checkItem,callBack);
    },
    /**
     * 通过id加载字典信息的API
     * @param flaw
     * @param callBack
     */
    getById(checkItemId,callBack){
        let url = this.BASE_URL + "/checkItem/queryById?checkItemId=" + checkItemId;
        request.get(url,null,callBack);
    },
    /**
     * 更新修改通过检测模板
     */
    updateCheckItemTemplate(checkItem,callBack){
        let url = this.BASE_URL + "/checkItem/updateByTemplate";
        request.post(url,checkItem,callBack);
    },
    /**
     * 修改字典信息的API
     * @param flaw
     * @param callBack
     */
    updateCheckItemId(checkItem,callBack){
        let url = this.BASE_URL + "/checkItem/update";
        request.post(url,checkItem,callBack);
    },
    /**
     *  删除字典的API
     * @param dictId
     * @param callBack
     */
    deleteCheckItem(checkItemId,callBack){
        request.get(this.BASE_URL + "/checkItem/delete?checkItemId=" + checkItemId,null,callBack);
    },
    /**
     * 批量删除字典的API
     * @param dictIds
     * @param callBack
     */
    deleteCheckItems(checkItemIds,callBack){
        let url = this.BASE_URL + "/checkItem/deletes?a=1";
        for (let i = 0; i < checkItemIds.length; i++){
            url += "&checkItemIds="+checkItemIds[i];
        }
        request.get(url,null,callBack);
    }
}
// 导出我们申明的dictrequest对象
export default FlawRequest;